define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'performance/performance/index' + location.search,
                    add_url: 'performance/performance/add',
                    edit_url: 'performance/performance/edit',
                    del_url: 'performance/performance/del',
                    multi_url: 'performance/performance/multi',
                    import_url: 'performance/performance/import',
                    table: 'performance',
                }
            });


            var table = $("#table");
            $(".btn-add").data("area", ["100%", "100%"]);

            //当内容渲染完成给编辑按钮添加`data-area`属性
            table.on('post-body.bs.table', function (e, settings, json, xhr) {
                $(".btn-editone").data("area", ["100%", "100%"]);
            });

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                Search: true,
                commonSearch: true,
                searchFormVisible: true,
                columns: [
                    [
                        { checkbox: true },
                        { field: 'id', title: __('Id'), operate: false },
                        { field: 'name', title: __('Name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content },
                        { field: 'createtime', title: __('Createtime'), operate: false, addclass: 'datetimerange', autocomplete: false, formatter: Table.api.formatter.datetime },
                        { field: 'status', title: __('Status'), searchList: { "0": __('Status 0'), "1": __('Status 1') }, formatter: Table.api.formatter.status },
                        // {field: 'shop_id', title: __('Shop_id')},
                        { field: 'staff_ids', title: __('Staff_ids'), operate: false, table: table, class: 'autocontent', formatter: Table.api.formatter.content },

                        // {field: 'gtype', title: __('Gtype'), searchList: {"0":__('Gtype 0'),"1":__('Gtype 1'),"2":__('Gtype 2')}, formatter: Table.api.formatter.normal},
                        // {field: 'ftype', title: __('Ftype'), searchList: {"0":__('Ftype 0'),"1":__('Ftype 1'),"2":__('Ftype 2')}, formatter: Table.api.formatter.normal},
                        // {field: 'i1type', title: __('I1type'), searchList: {"0":__('I1type 0'),"1":__('I1type 1'),"2":__('I1type 2')}, formatter: Table.api.formatter.normal},
                        // {field: 'i2type', title: __('I2type'), searchList: {"0":__('I2type 0'),"1":__('I2type 1'),"2":__('I2type 2')}, formatter: Table.api.formatter.normal},
                        // {field: 'i3type', title: __('I3type'), searchList: {"0":__('I3type 0'),"1":__('I3type 1'),"2":__('I3type 2')}, formatter: Table.api.formatter.normal},
                        // {field: 'sku_ids', title: __('Sku_ids'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'di1type', title: __('Di1type'), searchList: {"0":__('Di1type 0'),"1":__('Di1type 1'),"2":__('Di1type 2')}, formatter: Table.api.formatter.normal},
                        // {field: 'sku1_ids', title: __('Sku1_ids'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},

                        // {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'shop.id', title: __('Shop.id')},
                        // {field: 'shop.user_id', title: __('Shop.user_id')},
                        // {field: 'shop.shopname', title: __('Shop.shopname'), operate: 'LIKE'},
                        // {field: 'shop.keywords', title: __('Shop.keywords'), operate: 'LIKE'},
                        // {field: 'shop.description', title: __('Shop.description'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'shop.service_ids', title: __('Shop.service_ids'), operate: 'LIKE'},
                        // {field: 'shop.avatar', title: __('Shop.avatar'), operate: 'LIKE', events: Table.api.events.image, formatter: Table.api.formatter.image},
                        // {field: 'shop.state', title: __('Shop.state')},
                        // {field: 'shop.level', title: __('Shop.level')},
                        // {field: 'shop.islive', title: __('Shop.islive')},
                        // {field: 'shop.isself', title: __('Shop.isself')},
                        // {field: 'shop.city', title: __('Shop.city'), operate: 'LIKE'},
                        // {field: 'shop.return', title: __('Shop.return'), operate: 'LIKE'},
                        // {field: 'shop.like', title: __('Shop.like')},
                        // {field: 'shop.score_describe', title: __('Shop.score_describe'), operate:'BETWEEN'},
                        // {field: 'shop.score_service', title: __('Shop.score_service'), operate:'BETWEEN'},
                        // {field: 'shop.score_deliver', title: __('Shop.score_deliver'), operate:'BETWEEN'},
                        // {field: 'shop.score_logistics', title: __('Shop.score_logistics'), operate:'BETWEEN'},
                        // {field: 'shop.weigh', title: __('Shop.weigh')},
                        // {field: 'shop.verify', title: __('Shop.verify')},
                        // {field: 'shop.createtime', title: __('Shop.createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'shop.updatetime', title: __('Shop.updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'shop.deletetime', title: __('Shop.deletetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'shop.status', title: __('Shop.status'), formatter: Table.api.formatter.status},
                        // {field: 'shop.code', title: __('Shop.code'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'shop.type', title: __('Shop.type')},
                        // {field: 'shop.auth_id', title: __('Shop.auth_id')},
                        // {field: 'shop.person', title: __('Shop.person'), operate: 'LIKE'},
                        // {field: 'shop.telephone', title: __('Shop.telephone'), operate: 'LIKE'},
                        // {field: 'shop.staff_id', title: __('Shop.staff_id')},
                        // {field: 'shop.maturitytime', title: __('Shop.maturitytime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'shop.payment', title: __('Shop.payment'), operate:'BETWEEN'},
                        // {field: 'shop.settled', title: __('Shop.settled'), operate:'BETWEEN'},
                        // {field: 'shop.adds', title: __('Shop.adds'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        { field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        recyclebin: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    'dragsort_url': ''
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: 'performance/performance/recyclebin' + location.search,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        { checkbox: true },
                        { field: 'id', title: __('Id') },
                        { field: 'name', title: __('Name'), align: 'left' },
                        {
                            field: 'deletetime',
                            title: __('Deletetime'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            formatter: Table.api.formatter.datetime
                        },
                        {
                            field: 'operate',
                            width: '140px',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'Restore',
                                    text: __('Restore'),
                                    classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
                                    icon: 'fa fa-rotate-left',
                                    url: 'performance/performance/restore',
                                    refresh: true
                                },
                                {
                                    name: 'Destroy',
                                    text: __('Destroy'),
                                    classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
                                    icon: 'fa fa-times',
                                    url: 'performance/performance/destroy',
                                    refresh: true
                                }
                            ],
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },

        add: function () {

            $('.next-btn').click(function () {
                if ($('#c-name').val() == '') {
                    return layer.msg('请输入方案名称')
                }
                $('.basic-box').hide()
                $('.yuan-box').eq(1).addClass('yuan-active')
                $('.heng').addClass('heng-active')
                $('.scheme-box').show()
            })
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
